import React, { useEffect, useState } from 'react';
import { TreeSelect } from 'antd';
import request from '@/utils/request';

const PermissionTreeSelect: React.FC<{ value?: string; onChange?: (val: string) => void }> = ({ value, onChange }) => {
  const [treeData, setTreeData] = useState<any[]>([]);
  useEffect(() => {
    request.get('/permissions/tree').then(res => {
      // 兼容 axios 响应结构
      setTreeData(res.data ? res.data : res);
    });
  }, []);
  return (
    <TreeSelect
      treeData={treeData}
      value={value}
      onChange={onChange}
      placeholder="请选择权限"
      allowClear
      treeDefaultExpandAll
      style={{ width: '100%' }}
    />
  );
};

export default PermissionTreeSelect; 